<!-- 首页页面
codeslizhi
@email: 1664234934@qq.com
@Date: 2022 3 9
 -->
<template>
	<view class="index-button">
		<cu-custom class="bg-gradual-blue" :isBack="false">
			<block slot="content"> 寻物有我 </block>
		</cu-custom>
		<view class="wrap">  
			<!-- 轮播图 -->
			<swiper class="screen-swiper"  :indicator-dots="true"
				:circular="true" :autoplay="true" interval="5000" duration="500">
				<swiper-item v-for="(item,index) in swipers" :key="index">
					<image :src="item.img_url" mode="aspectFill"></image>
					<video :src="item.img_url" autoplay loop muted :show-play-btn="false" :controls="false"
						objectFit="cover" v-if="item.type=='video'"></video>
				</swiper-item>
			</swiper>

			<view class="page-box" >
				<view class="hot_goods">
					<!-- 文字滚动 -->
					<uni-notice-bar speed="50" showClose="true" showIcon="true" color="#87CEFF" scrollable="true" single="true"
						:text="Announcement"></uni-notice-bar>
				</view>
				
				<view class="order" v-for="(res, index) in goods" :key="res.id">
					<view class="top" @click="goGoodsDetatil(res.id)">
						<view class="left">
							<uni-text class="cuIcon-titles text-blue"></uni-text>
							<view class="store">{{ res.title }}</view>
							<!-- <u-icon name="arrow-right" color="rgb(203,203,203)" :size="26"></u-icon> -->
						</view>
						<!-- <view class="right"> 
							<text class="text-blue">丢失时间：{{ getdate(res.create_time) }}</text>
						</view> -->
					</view>
					<view class="left1"> 
							<text class="text-blue">丢失时间：{{ getdate(res.create_time) }}</text>
					</view> 

					<view class="item" @click="goGoodsDetatil(res.id)">
						<view class="left"> 
							<image :src="res.img_url ? res.img_url[0] : ''" mode="widthFix"></image>
						</view>

<!-- 						物品描述
						<view class="content">
							<view class="title u-line-2 text-bold">{{ res.imgdesc }}</view>
							 <view class="type">{{ res.imgdesc }}</view> 
							<view class="delivery-time">{{ res.desc }}</view> 
						</view> -->
						 
					</view>
					<u-line color="#f1f1f1" margin="24rpx 0 15rpx 0"></u-line>
					<view class="bottom">
						<view>
							<!-- <view class="cu-avatar-group" style="padding-left: 24rpx;">
								<view class="cu-avatar round" v-for="(item,index) in avatar" :key="index"
									:style="[{ backgroundImage:'url(' + avatar[index] + ')' }]"></view>
							</view> -->
							<text class="text-blue text-shadow"> 
								<text class="text-blue text-shadow" v-if="res.status == 0">状态：待审核</text>  
								<text class="text-blue text-shadow" v-if="res.status == 1">状态：待认领</text>    
								<text class="text-blue text-shadow" v-if="res.status == 2">状态：已完成</text>    
								<text class="text-blue text-shadow" v-if="res.status == 3">状态：审核失败</text>    
							</text>  
						</view>

						<view class="btnBox">
							<view @click="getClaim(res.id,res.title)" class="evaluate btn">认领</view>
						</view>
					</view>
				</view>
				<u-loadmore @loadmore="toLower" :status="loadStatus" icon-color="#2979ff"
										color="#2979ff" /> 
			</view>


		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				swipers: [],
				goods: [],//当前页面的数据
				percent: 50,
				activeColor: '#0081ff',
				striped: false,
				stripedActive: false,
				orderList: [
					[],
					[],
					[],
					[]
				],
				current: 0,
				swiperCurrent: 0,
				tabsHeight: 0,
				dx: 0,
				loadStatus: ['', '', '', ''],
				Announcement:"",//公告
				page:0,//记录当前页
				loadStatuss:"loadmores",//请求下拉到底部的节流阀
			};
		},
		onLoad() {
			this.getSwipers() 
			this.getHotGoods()
			this.getAnnouncement()
		},
		computed: {},
		methods: {
			// 获取轮播图的数据 
			async getSwipers() {
				let opts2 = {
						url: ':8023/public/v1/banner', 
						method: 'GET'   
				} 
				const res = await this.$httpTokenRequest(opts2);
				// console.log(res.data.data)  
				this.swipers = res.data.data.data;   
				// console.log(this.swipers);
			},
			//获取通知列表公告
			async getAnnouncement() { 
				let opts = { 
						url: ':8023/public/v1/notice', 
						method: 'GET'    
				} 
				const res = await this.$httpTokenRequest(opts); 
				this.Announcement = res.data.data.data[0].Content;     
			},
			// 获取热门物品的信息
			async getHotGoods() {
				// const res = await this.$myRequest({
				// 	url: ':8022/o/v1/order'
				// })
				const res = await this.$httpTokenRequest({ 
					url: ':8022/o/v1/order?type=0&status=1&page=0',  
					method: 'GET' 
				})
				console.log(res.data) 
				this.goods = res.data.data.data;
				// console.log(this.goods) 
			},
			// 导航到物品详情页
			goGoodsDetatil(id) {
				uni.navigateTo({
					url: '/pages/goods-detail/goods-detail?id=' + id
				})
			},
			// 
			getClaim(id,title) {
				console.log(id)
				uni.navigateTo({ 
					url: '/pages/Claim/index?id=' + id + '&title=' + title  
				})
			},
			// 页面进去时执行
			onShow() {
				this.getHotGoods()
			},
			//时间转换
			getdate(strDate1) {
				const date = new Date(strDate1)
				var strDate = date.getFullYear() + '年' 
				strDate += date.getMonth() + 1 + '月'
				strDate += date.getDate() + '号'
				// strDate += date.getHours()  
				// strDate += date.getMinutes() + ':' 
				// strDate += date.getSeconds()
     			return strDate 
			},
			async onReachBottom() {
				if (this.loadStatuss !== "nomore") {
					this.loadStatuss = "loading"
					this.page++ 
					const res = await this.$httpTokenRequest({ 
						url: ':8022/o/v1/order?type=0&status=1&page=' + this.page,   
						method: 'GET'
					}) 
					// console.log(res.data.data.data.length);
					this.goods.push(...res.data.data.data) 
					this.loadStatuss = "loadmores"
					if (res.data.data.data.length < 10) { //没有更多数据了
						this.loadStatuss = "nomore" 
					}
				}
			},
		}
	};
</script>

<style lang="scss" scoped>
	/* #ifndef H5 */
	page {
		height: 100%;
		background-color: #f2f2f2;
	}

	/* #endif */
</style>

<style lang="scss" scoped>
	.page-top {
		height: 500rpx; 
		background-image: linear-gradient(45deg, #ffd23c, #ffd23c);
	}
	.home {
		swiper {
			width: 750rps;
			height: 380rps;

			image {
				height: 100%;
				width: 100%;
			}
		}
	}

	.hot_goods {
		background: #eee;
		overflow: hidden;
		margin-top: 10px;

		.title {
			height: 50px;
			line-height: 50px;
			color: #87CEFF;
			text-align: center;
			letter-spacing: 20px;
			background-color: #fff;
			margin: 7rpx 0;
		}
	}

	.order {
		width: 710rpx;
		background-color: #ffffff;
		margin: 20rpx auto;
		border-radius: 20rpx;
		box-sizing: border-box;
		padding: 20rpx;
		font-size: 28rpx;
		// float: left;
		.top {
			display: flex;
			justify-content: space-between;

			.left {
				display: flex;
				align-items: center;

				.store {
					margin: 8rpx 10rpx 10rpx;
					font-size: 34rpx;
					font-weight: bold;
				}
			}

			.right {
				color: $u-type-warning-dark;

				.progressBox {
					width: 150rpx;
					float: right;
				}
			}
		}

		.item {
			display: flex;
			margin: 20rpx 0 0;

			.left {
				margin-right: 20rpx;

				image {
					width: 260rpx;
					height: 190rpx;
					border-radius: 10rpx;
				}
			}

			.content {
				
				.title {
					font-size: 28rpx;
					line-height: 45rpx;
				}

				.type {
					margin: 6rpx 0;
					font-size: 24rpx;
					color: $u-tips-color;
					text-overflow: -o-ellipsis-lastline;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 3;
					line-clamp: 3;
					-webkit-box-orient: vertical;
				}

				.delivery-time {
					color: #000;
					font-size: 34rpx;
					
				}
			}

			.right {
				margin-left: 10rpx;
				padding-top: 20rpx;
				text-align: right;

				.decimal {
					font-size: 24rpx;
					margin-top: 4rpx;
				}

				.number {
					color: $u-tips-color;
					font-size: 24rpx;
				}
			}
		}

		.total {
			margin-top: 20rpx;
			text-align: right;
			font-size: 24rpx;

			.total-price {
				font-size: 32rpx;
			}
		}

		.bottom {
			line-height: 70rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.btnBox {
				width: 150rpx;
				display: flex;
				justify-content: space-between;

				.btn {
					line-height: 52rpx;
					width: 140rpx;
					border-radius: 12rpx;
					border: 2rpx solid $u-tips-color;
					font-size: 26rpx;
					text-align: center;
					color: $u-tips-color;
				}

				.evaluate {
					color: $u-type-primary;
					border-color: $u-type-primary;
				}
			}
		}
	}

	.centre {
		text-align: center;
		margin: 200rpx auto;
		font-size: 32rpx;

		image {
			width: 300rpx;
			border-radius: 50%;
			margin: 0 auto;
		}

		.tips {
			font-size: 24rpx;
			color: #999999;
			margin-top: 20rpx;
		}

		.btn {
			margin: 80rpx auto;
			width: 200rpx;
			border-radius: 32rpx;
			line-height: 64rpx;
			color: #ffffff;
			font-size: 26rpx;
			background: #ffd23c
		}
	}

	.wrap {
		// position: absolute;
		// top:100px;
		// z-index: 3;
		display: flex;
		flex-direction: column;
		// height: calc(100vh - var(--window-top));
		width: 100%;
		// background-color: pink;
		height: calc(100% - 50px - env(safe-area-inset-bottom));
	}
	
	.swiper-box {
		flex: 1;
	}

	.swiper-item {
		height: 100%;
	}
	.left1 {
		margin-top: 8rpx; 
		margin-left: 10rpx; 
	}
	.index-button {
		height: calc(100% - 50px - env(safe-area-inset-bottom));
	}
	// .page-box {
	// 	height: calc(100% - 50px - env(safe-area-inset-bottom));
	// }
	.bg-gradual-blue {
		background-image: linear-gradient(45deg, #0081ff, #1cbbb4) !important;
		color: #ffffff; 
	}
</style>
